package com.yes_iot.controller;

import com.yes_iot.entity.VisualMoudleLibrary;
import com.yes_iot.util.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.UUID;

@RestController
@RequestMapping("/yesiot")
@Slf4j
@CrossOrigin
public class VisualMoudleLibraryController extends BaseController{

    @RequestMapping(value = "/findVisualMoudelLibrary", method = RequestMethod.GET)
    public Result findVisualMoudelLibrary(@RequestParam String parentId)  {
        try {
            List<VisualMoudleLibrary> visualMoudleLibraryList= visualMoudleLibraryService.findVisualMoudelLibraryByVisualDisplayParentId(parentId);
            return Result.succeed(visualMoudleLibraryList,"查询成功");
        } catch (Exception e) {
            e.getMessage();
            return Result.failed(e.getMessage());
        }
    }
    @RequestMapping(value = "/visual/moudle/library", method = RequestMethod.DELETE)
    public Result delete(@RequestParam String id)  {
        try {
            visualMoudleLibraryService.delete(id);
            return Result.succeed("删除成功");
        } catch (Exception e) {
            e.getMessage();
            return Result.failed(e.getMessage());
        }
    }
    @RequestMapping(value = "/visual/moudle/library/save", method = RequestMethod.POST)
    public Result delete(@RequestBody VisualMoudleLibrary visualMoudleLibrary)  {
        try {
            UUID id = visualMoudleLibrary.getId();
            if (id==null){
                visualMoudleLibrary.setId(UUID.randomUUID());
                visualMoudleLibrary.setCreatedTime(System.currentTimeMillis());
            }

            return Result.succeed(visualMoudleLibraryService.save(visualMoudleLibrary),"删除成功");
        } catch (Exception e) {
            e.getMessage();
            return Result.failed(e.getMessage());
        }
    }
}
